<template>
  <div class="mod-config">
    <basic-container>
      <navigation :sign="{a:true,b:false,c:false,d:false,e:false}"></navigation>
      <div v-if="ymLoad" class="duiQitishi">
        <div class="tiShiTu">
          <img src="/images/qita/tishi.png" width="300">
        </div>
        <div class="tiShi">
          <div><b>您现在不是任何部门的奖金管理人员，无法进行人员奖惩维护的操作</b></div>
          <div class="font18 mt10">您可以通知系统管理员，为您设置具体的奖金管理部门！</div>
        </div>
      </div>
      <div class="boxsty zhiBiao" v-else>
        <!-- <div class="flex justifyContentSpaceBetween">
          <div class="tabletext">人员奖惩维护</div>
          <div class="tablelink">
            <el-link icon="el-icon-plus" v-if="permissions.jiangjin_jiangjingrjcjlb_add" type="primary"
                     @click="addOrUpdateHandle()" :underline="false" :disabled="deptId===''">新增个人奖惩
            </el-link>
            <el-link icon="el-icon-plus" v-if="permissions.jiangjin_jiangjingrjcjlb_add" type="primary"
                     @click="addOrUpdateAll()" :underline="false" :disabled="deptId===''">批量添加奖惩
            </el-link>
          </div>
        </div> -->
        <div v-show="isEdit==1">
          <div :height="searchheight">
                <span
                  style="float: right; margin-top: -30px; cursor: pointer"
                  @click="searchchangeadvanced"
                >{{ searchadvanced ? "查询条件收起" : "查询条件展开" }}
                    <i
                      :class="
                        searchadvanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'
                    "
                    />
                </span>
            <div v-show="searchadvanced">
              <div class="flex">
                <div class="mt20" style="height: 72px;">
                  <b>负责部门：</b>
                  <el-select v-model="deptId" placeholder="请选择负责部门" class="xiaLa mr20" style="width: 300px"
                             @change="switchDepartment">
                    <el-option v-for="(item,index) in fzbmData" :key="index" :label="item.deptName" :value="item.deptId">
                    </el-option>
                  </el-select>
                </div>
                <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()" class="form-inline">
                  <el-form-item label="姓名">
                    <el-input v-model="dataForm.userName" placeholder="姓名" style="width: 160px;"></el-input>
                  </el-form-item>
                  <el-form-item label="编号">
                    <el-input v-model="dataForm.userCode" placeholder="员工编号"></el-input>
                  </el-form-item>
                  <el-form-item label="奖金项">
                    <el-select v-model="dataForm.jjxName" placeholder="选择奖金项" clearable class="xiaLa"
                               style="width: 160px;">
                      <el-option v-for="(item,index) in jjxOptions " :key="index" :label="item.label" :value="item.label">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="状态">
                    <el-select v-model="dataForm.jjFfzt" placeholder="选择发放状态" clearable class="xiaLa"
                               style="width: 160px;">
                      <el-option v-for="(item,index) in  options " :key="index" :label="item.label" :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item>
                    <el-button icon="el-icon-search" type="primary" :disabled="deptId===''" class="marginLeft" plain
                               @click="getDataList(1)">检索
                    </el-button>
                  </el-form-item>
                  <!-- <el-form-item>
                    <el-button @click="temopDow" type="primary" plain>模板下载</el-button>
                  </el-form-item>
                  <el-form-item>
                    <el-upload class="upload-demo" :before-upload="beforeAvatarUpload" :show-file-list="false"
                              accept=".xlsx, .xls" :headers="headers" action="/admin/sys-file/upload"
                              :on-success="handleUploadSuccess">
                      <el-button type="primary" plain>导入</el-button>
                    </el-upload>
                  </el-form-item> -->
                </el-form>
              </div>
            </div>
          </div>
          <div>
            <el-tooltip
              class="item"
              effect="dark"
              content="导入"
              placement="top"
            >
              <el-upload
                action="/admin/sys-file/upload"
                accept=".xlsx, .xls"
                :headers="headers"
                class="upload-demo inline-block"
                :before-upload="beforeAvatarUpload"
                :on-success="handleUploadSuccess"
                :show-file-list="false"
                style="padding-right:10px">
                <el-button icon="el-icon-upload" size="small" type="success" circle></el-button>
              </el-upload>
            </el-tooltip>
            <!-- <el-tooltip
              class="item"
              effect="dark"
              content="新增个人奖惩"
              placement="top"
              v-model="isShow"
            >
              <el-button
                icon="el-icon-plus"
                type="primary"
                @click="addOrUpdateHandle(0)"
                :disabled="deptId===''"
                circle
              ></el-button>
            </el-tooltip> -->
            <el-tooltip
              class="item"
              effect="dark"
              content="添加奖惩信息"
              placement="bottom"
              v-model="isShowTwo"
            >
              <el-button
                icon="el-icon-plus"
                type="primary"
                :disabled="deptId===''"
                circle
                @click="addOrUpdateAll()"
              ></el-button>
            </el-tooltip>
            <el-tooltip
              class="item"
              effect="dark"
              content="模板下载"
              placement="top"
            >
              <el-button
                icon="el-icon-download"
                type="info"
                circle
                @click="temopDow"
              ></el-button>
            </el-tooltip>
            <el-tooltip
              class="item"
              effect="dark"
              content="修改"
              placement="top"
            >
              <el-button
                icon="el-icon-edit"
                type="warning"
                circle
                v-if="permissions.jiangjin_jiangjingrjcjlb_edit"
                @click="editBatch"
              ></el-button>
            </el-tooltip>
            <!--原来的修改方法 @click="addOrUpdateHandle(1)" -->
            <!-- <el-tooltip
                class="item"
                effect="dark"
                content="启用"
                placement="top"
            >
                <el-button
                icon="el-icon-video-pause"
                type="success"
                circle
                ></el-button>
            </el-tooltip> -->
            <el-tooltip
              class="item"
              effect="dark"
              content="批量删除"
              placement="top-start"
            >
              <el-button
                type="danger"
                icon="el-icon-delete"
                v-if="permissions.jiangjin_jiangjingrjcjlb_del"
                @click="deleteHandle()"
                circle
              ></el-button>
            </el-tooltip>
            <div class="pull-right">
              <el-button type="primary" plain @click="onObtain">获取考核数据</el-button>
              <!-- <el-button type="primary" plain @click="rewardsTip">奖惩提示</el-button> -->
              <el-button @click="putgetjjxBydept" type="primary" plain>配置转换系数</el-button>
            </div>
          </div>
          <el-table :data="dataList" ref="table" header-align="center" v-loading="dataListLoading" stripe class="avue-crud" @row-dblclick="handleRowDblclick" tooltip-effect="dark" @cell-click="handleRowClick" border height="460px" style="margin-top:20px;">
            <el-table-column type="selection" width="55" header-align="center" align="center"></el-table-column>
            <el-table-column prop="" label="序号" :formatter="nShowIndex" align="center" width="60"></el-table-column>
            <el-table-column prop="userCode" label="人员编号" min-width="100" align="center"></el-table-column>
            <el-table-column prop="userName" label="人员名称" min-width="100" align="center"></el-table-column>

            <el-table-column prop="jjxName" label="奖金项名称" min-width="150" align="center">
              <template slot-scope="scope">
                <div v-if="scope.row.id==dbclickRowId">
                  <el-select :clearable="true" v-model="scope.row.jjxId" @change="handleSaveRowEdit(scope.row,scope.row.jjxId,'奖金项')" placeholder="请选择" class="xiaLa" style="width:100%;">
                    <el-option v-for="(item,index) in jjxOptions " :key="index" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </div>
                <div v-else>{{scope.row.jjxName}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="jjFz" label="奖惩分值" min-width="100" align="center"></el-table-column>
            <el-table-column prop="lx" label="类型" min-width="100" align="center">
              <template slot-scope="scope">
                <div v-if="scope.row.id==dbclickRowId">
                  <el-select v-model="scope.row.lx" @change="handleSaveRowEdit(scope.row,scope.row.lx,'类型')">
                    <el-option label="奖励" value="奖励"></el-option>
                    <el-option label="惩罚" value="惩罚"></el-option>
                  </el-select>
                </div>
                <div v-else>{{scope.row.lx}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="jjJe" label="奖惩金额" min-width="120" :formatter="nFormatterShow" align="center">
              <template slot-scope="scope">
                <div v-if="scope.row.id==dbclickRowId">
                  <el-input-number v-model="scope.row.jjJe" :min="0"  @change="handleSaveRowEdit(scope.row,scope.row.jjJe,'奖惩金额')" :precision="2" :step="100" style="width:100%;"></el-input-number>
                </div>
                <div v-else>{{scope.row.jjJe?scope.row.jjJe.toFixed(2):scope.row.jjJe}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="jjDate" label="奖惩时间" min-width="160" :formatter="fTTable" align="center">
              <template slot-scope="scope">
                <div v-if="scope.row.id==dbclickRowId">
                  <el-date-picker v-model="scope.row.jjDate"  @change="handleSaveRowEdit(scope.row,scope.row.jjDate,'奖惩时间')" placeholder="奖惩时间" style="width:100%;" type="datetime"
                                  :picker-options="expireTimeOption" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
                </div>
                <div v-else>{{scope.row.jjDate?$moment(scope.row.jjDate).format("YYYY-MM-DD"):scope.row.jjDate}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="jjFfzt" label="放发状态" min-width="90" align="center"></el-table-column>
            <el-table-column prop="jjFfzt" label="启用状态" min-width="140" align="center">
              <template slot-scope="scope">
                <el-switch
                  @change="handleSaveRowEdit(scope.row,scope.row.enableStatus,'启用状态')"
                  v-model="scope.row.enableStatus"
                  active-color="#13ce66"
                  inactive-color="#ff4949"
                  active-text="启用"
                  inactive-text="停用"
                  :disabled="scope.row.jjFfzt=='已使用'"
                  :active-value="0"
                  :inactive-value="1">
                </el-switch>
              </template>
            </el-table-column>
            <el-table-column prop="jjSm" label="奖惩说明" show-overflow-tooltip min-width="180" align="center">
              <template slot-scope="scope">
                <div v-if="scope.row.id==dbclickRowId">
                  <el-input v-model="scope.row.jjSm" placeholder="奖惩说明" @change="handleSaveRowEdit(scope.row,scope.row.jjSm,'奖惩说明')" :rows="3" type="textarea" style="width:100%;" show-word-limit maxlength="250"></el-input>
                </div>
                <span v-else>
                  {{scope.row.jjSm}}
                </span>
              </template>
            </el-table-column>
            <el-table-column min-width="120" label="修改金额备注" prop="jjjebz">
              <template slot-scope="scope">
                <div v-if="scope.row.id==dbclickRowId">
                  <el-input v-model="scope.row.jjjebz" placeholder="修改金额备注" @change="handleSaveRowEdit(scope.row,scope.row.jjjebz,'修改金额备注')" :rows="3" type="textarea" style="width:100%;" show-word-limit maxlength="250"></el-input>
                </div>
                <span v-else>
                  {{scope.row.jjjebz}}
                </span>
              </template>
            </el-table-column>
            <el-table-column label="文件上传" width="100">
              <template slot-scope="scope">
                <el-button type="primary" plain @click="btnAttachment(scope.row)">附件管理</el-button>
                <!-- <el-button :disabled="scope.row.jjFfzt==='已发放'" v-if="permissions.jiangjin_jiangjingrjcjlb_edit"
                          type="primary" plain @click="addOrUpdateHandle(scope.row.id)">修改
                </el-button>
                <el-button :disabled="scope.row.jjFfzt==='已发放'" v-if="permissions.jiangjin_jiangjingrjcjlb_del"
                          type="danger" plain @click="deleteHandle(scope.row.id)">删除
                </el-button> -->
              </template>
            </el-table-column>
          </el-table>

          <div class="avue-crud__pagination">
            <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex"
                           :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" background
                           layout="total, sizes, prev, pager, next, jumper">
            </el-pagination>
          </div>
        </div>
        <!--批量修改-->
        <batchEditCard  v-show="isEdit==2" ref='batchEdit' @batchChild='batchChild'></batchEditCard>
      </div>
      <!-- 弹窗, 新增 -->
      <table-form v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></table-form>
      <!-- 批量添加 -->
      <table-form-all v-if="addOrUpdateAllVisible" ref="addOrUpdateAll" @refreshDataList="getDataList"></table-form-all>
      <!-- 批量导入返回结果集 -->
      <dataIndex ref="dataIndex" @refreshDataList="getDataList"></dataIndex>
      <!--奖惩提示-->
      <rewardsPunishmentCard ref='rewardsPunishment'></rewardsPunishmentCard>
      <!-- 附件管理 -->
      <fujian ref='fujian'></fujian>
      <el-dialog
        title="配置奖金系数"
        :visible.sync="bonusDialogVisible"
        width="32%"
        center>
        <div>
          <el-table :data="configurationList" @selection-change="handleSelectionChange" ref="table2" header-align="center"  stripe class="avue-crud" tooltip-effect="dark">
            <el-table-column type="selection"  width="55" align="center"></el-table-column>
            <el-table-column prop="" label="序号" :formatter="nShowIndex" width="70" align="center"></el-table-column>
            <el-table-column prop="jjxMc" label="奖金项名称" min-width="100" align="center"></el-table-column>
            <el-table-column prop="jjFz" label="分值" min-width="100" align="center">
              <template slot-scope="scope">
                <el-input-number v-model="scope.row.jjFz" placeholder="" @change="changValuejjFz(scope.row.jjFz)"></el-input-number>
              </template>
            </el-table-column>
            <el-table-column prop="jjJe" label="金额(元)" min-width="100" align="center">
              <template slot-scope="scope">
                <el-input-number v-model="scope.row.jjJe" placeholder="" @change="changValuejjJe(scope.row.jjJe)"></el-input-number>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="bonusFactor">确 定</el-button>
          <el-button @click="bonusDialogVisible = false">取 消</el-button>
        </span>
      </el-dialog>
      <!--获取考核数据-->
      <el-dialog
        title="获取考核数据"
        :visible.sync="obtainDialogVisible"
        width="60%"
        :close-on-click-modal="false"
        center>
        <div>
          <el-form ref="form" :model="obtainForm" label-width="80px">
            <el-form-item label="考核周期">
              <el-select v-model="obtainForm.obtain" placeholder="请选择考核周期" @change="obtainChange">
                <el-option v-for="item in obtainList" :label="item" :value="item"></el-option>
              </el-select>
            </el-form-item>
          </el-form>
          <el-table
          v-if="obtainForm.obtain"
          :data="obtainTableData"
          align="center"
          style="width: 100%">
          <el-table-column
            prop="userCode"
            label="人员编号"
            align="center"
            width="180">
          </el-table-column>
          <el-table-column
            prop="userName"
            label="人员名称"
            align="center"
            width="180">
          </el-table-column>
          <el-table-column
            prop="lx"
            align="center"
            label="类型">
          </el-table-column>
          <el-table-column
            prop="jjxName"
            align="center"
            min-width="110"
            label="奖金项名称">
          </el-table-column>
          <el-table-column
            prop="jjFz"
            align="center"
            min-width="90"
            label="奖惩分值">
          </el-table-column>
          <el-table-column
            prop="jjJe"
            align="center"
            min-width="90"
            label="奖惩金额">
          </el-table-column>
          <el-table-column
            prop="jjDate"
            align="center"
            min-width="110"
            label="奖惩时间">
            <template slot-scope="scope">
              <span>{{scope.row.jjDate?$moment(scope.row.jjDate).format("YYYY-MM-DD"):scope.row.jjDate}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="jjFfzt"
            align="center"
            min-width="90"
            label="放发状态">
          </el-table-column>
          <el-table-column
            prop="enableStatus"
            align="center"
            min-width="90"
            label="启用状态">
            <template slot-scope="scope">
              <span>{{scope.row.enableStatus==0?'启用':'停用'}}</span>
            </template>
          </el-table-column>
        </el-table>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="onbath">确 定</el-button>
          <el-button @click="obtainDialogVisible = false">取 消</el-button>
        </span>
      </el-dialog>
    </basic-container>
  </div>
</template>

<script>
import {
  fetchList,
  deleteBatch,
  putObj,
  getjjxBydept,
  savejcData,
  getRqList,
  getDataList,
  bath
} from '@/api/jiangjin/jiangjingrjcjlb'

import TableForm from './jiangjingrjcjlb-form'
import TableFormAll from './batchGrjcjlb'
import batchEditCard from './batchEditCard'
import rewardsPunishmentCard from './rewardsPunishmentCard'
import {
  mapGetters
} from 'vuex'
import {
  getJiangJinBm
} from '@/api/admin/dept'
import {getJjDeptJjx} from '@/api/jiangjin/jiangjinjjxxxb'
import dataIndex from './importDataInfo/dataIndex'
import store from '@/store'
import request from '@/router/axios'
import fujian from './fujian'

export default {
  data() {
    return {
      expireTimeOption: {
        disabledDate(date) {
          //disabledDate 文档上：设置禁用状态，参数为当前日期，要求返回 Boolean
          return (
            date.getTime() < new Date(new Date().getFullYear(), 0, 1).getTime() ||
            date.getTime() > new Date(new Date().getFullYear(), 11, 31).getTime()
          );
        }
      },
      headers: {
        Authorization: 'Bearer ' + store.getters.access_token
      },
      dataForm: {
        userName: '',
        userCode: '',
        jjFfzt: '',
        jjDeptId: ''
      },
      fzbmData: [],
      options: [{
        value: '未使用',
        label: '未使用'
      }, {
        value: '已使用',
        label: '已使用'
      }, {
        value: '使用中',
        label: '使用中'
      }],
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      addOrUpdateVisible: false,
      addOrUpdateAllVisible: false,
      deptId: '', //负责部门ID
      deptName: '', //负责部门名称
      ymLoad:false,
      searchadvanced: true,
      searchheight: "0",
      isShow: true,
      isShowTwo:true,
      jjxOptions: [],
      dbclickRowId:"",
      verityName:'',
      bonusDialogVisible:false,
      configurationList:[],
      isEdit:1,
      chooseList:[],
      obtainDialogVisible:false,
      obtainForm:{},
      obtainList:[],
      obtainTableData:[]
    }
  },
  components: {
    TableForm,
    TableFormAll,
    dataIndex,
    rewardsPunishmentCard,
    batchEditCard,
    fujian
  },
  created() {
  },
  mounted() {
    this.getJiangJinJg();
  },
  computed: {
    ...mapGetters(['permissions'])
  },
  methods: {
    onbath(){
      bath(this.obtainTableData).then(res=>{
        if(res.data.code==0){
          this.$message.closeAll()
          this.$message.success("获取成功!")
          this.obtainDialogVisible=false;
          this.obtainTableData=[]
          this.getDataList()
          this.obtainForm.obtain=""
        }
      })
    },
    ongetRqList(){
      getRqList().then(res=>{
        this.obtainList=res.data.data
      })
    },
    //选择考核周期
    obtainChange(){
      console.log(this.obtainForm.obtain.replace(/-/g,''))
      var param={
        rqstr:this.obtainForm.obtain.replace(/-/g,'')
      }
      getDataList(param).then(res=>{
        this.obtainTableData=res.data.data
      })
    },
    //获取考核数据
    onObtain(){
      this.obtainDialogVisible=true
      this.ongetRqList()
    },
    searchchangeadvanced() {
      this.searchadvanced = !this.searchadvanced;
      if (this.searchadvanced) {
        this.searchheight = "50";
      }
    },
    //附件管理
    btnAttachment(row){
        this.$nextTick(() => {
        this.$refs.fujian.init(row.id);
      });
      },
    //配置奖金系数获取奖金项
    putgetjjxBydept(){
      getjjxBydept().then(res=>{
        this.bonusDialogVisible=true
        this.configurationList=res.data.data
      })
    },
    //配置奖金系数
    bonusFactor(){
      savejcData(this.configurationList).then(res=>{
        if(res.data.code==0){
          this.$message.success('保存成功!')
          this.bonusDialogVisible=false
          this.getDataList()
        }
      })
    },
    //获取奖金管理人机构
    getJiangJinJg() {
      getJiangJinBm().then(res => {
        if (res.data.data != null && res.data.data.length > 0) {
          this.deptId = "";
          this.deptName = "";
          this.deptId = res.data.data[0].deptId;
          this.deptName = res.data.data[0].name;
          this.fzbmData = res.data.data;
          this.ymLoad = false;
          this.getDataList();
          this.getJjDeptJjx()
        } else {
          this.$notify.closeAll();
          this.$notify.error("没有相关负责部门")
          this.deptName = "无相关负责部门";
          this.ymLoad = true;
        }
      }).catch(err =>{
        this.ymLoad = true;
      });
    },
    //管理部门切换
    switchDepartment(deptId) {
      for (var a in this.fzbmData) {
        if (this.fzbmData[a].deptId == deptId) {
          this.deptId = this.fzbmData[a].deptId;
          this.deptName = this.fzbmData[a].deptName;
          this.getDataList();
          this.getJjDeptJjx()
          break;
        }
      }
    },
    //列显示重新定义
    nFormatterShow(row, column, cellValue, index) {
      if (cellValue) {
        return cellValue.toFixed(2);
      } else {
        return cellValue;
      }
    },
    nShowIndex(row, column, cellValue, index) {
      return index + 1 + this.pageSize*(this.pageIndex-1);

    },
    fTTable(row, column, cellValue, index) {
      if (cellValue) {
        return this.$moment(cellValue).format("YYYY-MM-DD");
      } else {
        return cellValue;
      }
    },

    // 获取数据列表
    getDataList(page) {
      if (page){
        this.pageIndex = page
      }
      this.dataListLoading = true;
      this.$set(this.dataForm, "jjDeptId", this.deptId);
      fetchList(Object.assign({
        current: this.pageIndex,
        size: this.pageSize
      }, this.dataForm)).then(response => {
        this.dataList = response.data.data.records;
        this.totalPage = response.data.data.total;
        this.dataListLoading = false
      })
    },
    //行双击触发单条数据编辑
    handleRowDblclick(row, column, cell, event){
      if(row.jjFfzt=='已使用'){
        this.$message.closeAll()
        this.$message.warning('已使用的数据不能再修改!')
        return false
      }
      if(this.verityName){
        this.$notify.closeAll();
        this.$notify.warning(this.verityName+'不能为空！');
        return false;
      }
      this.dbclickRowId=row.id;
      // this.dataList=this.dataList.map(item=>{
      //   if(item.id==row.id){
      //     item.editCell=true;
      //   }else{
      //     item.editCell=false;
      //   }
      //   return item;
      // })
    },
    //行单击为了去除行编辑框状态
    handleRowClick(row, column, cell, event){
      if(this.verityName){
        this.$notify.closeAll();
        this.$notify.warning(this.verityName+'不能为空！');
        return false;
      }
      this.dbclickRowId=row.id==this.dbclickRowId?this.dbclickRowId:"";
    },
    //保存行编辑
    handleSaveRowEdit(row,prop,propName){
      if(propName=='启用状态'){
        if(this.verityName){
          this.$notify.closeAll();
          this.$notify.warning(propName+'不能为空！');
          var index=this.dataList.findIndex(item=>item.id==row.id);
          this.dataList[index].enableStatus=this.dataList[index].enableStatus==1?0:1;
          return false;
        }
      }else if(!prop){
        this.$notify.closeAll();
        this.$notify.warning(propName+'不能为空！');
        this.verityName=propName;
        return false;
      }
      this.verityName='';
      var jjObj=this.jjxOptions.find(item=>item.value==row.jjxId);
      if(jjObj){
        row.jjxName=jjObj.label;
      }
      const ljjJe = row.jjJe;
      const ljjFz = row.jjFz;
      // if (ljjJe >= 0) {
      //   this.dataForm.lx = "奖励";
      // } else {
      //   this.dataForm.lx = "惩罚";
      // }
      this.dataForm.jjJe = Math.abs(ljjJe);
      this.dataForm.jjFz = Math.abs(ljjFz);
      putObj(row).then(data => {
        this.$notify.closeAll();
        this.$notify.success('修改成功')
        //暂时不通过系统刷新页面;
      }).catch(() => {

      });
    },
    handleSelectionChange(list){
      this.chooseList = list;
    },
    changValuejjFz(val){
      this.chooseList.forEach(ele=>{
        ele.jjFz = val;
      })
    },
    changValuejjJe(val){
      this.chooseList.forEach(ele=>{
        ele.jjJe = val;
      })
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },
    //获取奖金项列表
    getJjDeptJjx(){
      console.log(this.deptId)
      getJjDeptJjx(this.deptId).then(res => {
        const xData = res.data.data;
        this.jjxOptions = [];
        xData.map(item => {
          this.jjxOptions.push({
            value: item.id,
            label: item.jjxMc
          })
        })
      })
    },
    //奖惩提示
    rewardsTip(){
      // var data=this.$refs.table.selection
      //   if (data.length == 0) {
      //     this.$message.closeAll();
      //     this.$message.error("请选择一条数据！");
      //     return;
      //   }
      //   if (data.length >1) {
      //     this.$message.closeAll();
      //     this.$message.error("只能选择一条数据！");
      //     return;
      //   }
      //   if(data.length==1){
      //     this.addOrUpdateVisible = true;
      //     this.$nextTick(() => {
      //       this.$refs.rewardsPunishment.init(data[0].id)
      //     })
      //   }
      this.$nextTick(() => {
        this.$refs.rewardsPunishment.init()
      })

    },
    // 新增
    addOrUpdateHandle(flag) {
      if(flag==0){
        this.addOrUpdateVisible = true;
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init('', this.deptId)
        })
      }
      if(flag==1){
        var data=this.$refs.table.selection
        //console.log(data.length)
        if (data.length == 0) {
          this.$message.closeAll();
          this.$message.error("请选择一条要修改的数据！");
          return;
        }
        if (data.length >1) {
          this.$message.closeAll();
          this.$message.error("只能选择一条数据修改！");
          return;
        }
        if(data.length==1){
          this.addOrUpdateVisible = true;
          this.$nextTick(() => {
            this.$refs.addOrUpdate.init(data[0].id, this.deptId)
          })
        }
      }


    },
    addOrUpdateAll() {
      this.addOrUpdateAllVisible = true;
      this.$nextTick(() => {
        this.$refs.addOrUpdateAll.init(this.deptId)
      })
    },
    //批量修改
    editBatch(){
      var data=this.$refs.table.selection
      var ids=[];
      var jjFfzt=[]
      if(jjFfzt.length>0){
        jjFfzt=data.filter(item=>{
          return item.jjFfzt=='已发放'
        })
      }
      if(jjFfzt.length>0){
        this.$message.closeAll();
        this.$message.error("修改的数据中有已发放的数据!");
        return;
      }
      if(data.length>0){
        ids=data.map(item=>{
          return item.id
        })
      }
      this.$nextTick(()=>{
        this.isEdit=2
        this.$refs.batchEdit.init(ids)
      })
    },
    batchChild(){
      this.isEdit=1;
      this.getDataList()
    },
    // 删除
    deleteHandle() {
      var data=this.$refs.table.selection
      if (data.length == 0) {
        this.$message.closeAll();
        this.$message.error("请选择一条要删除的数据！");
        return;
      }
      var jjFfzt=[]
      jjFfzt=data.filter(item=>{
        return item.jjFfzt=='已发放'
      })

      if(jjFfzt.length>0){
        this.$message.closeAll();
        this.$message.error("删除的数据中有已发放的数据!");
        return;
      }
      var ids=data.map(item=>{
        return item.id
      })


      var params={
        ids:ids.toString()
      }
      this.$confirm('是否确认删除', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function () {
        return deleteBatch(params)
      }).then(data => {
        this.$notify.closeAll();
        this.$notify.success('删除成功')
        if(this.dataList.length==1&&this.pageIndex!=1){
          this.pageIndex-=1;
        }
        this.getDataList()
      })
    },

    temopDow() {
      window.location.href = '../../static/人员奖惩导入.xlsx'
    },
    /**
     * 文件上传前
     */
    beforeAvatarUpload(file) {
      this.loading = this.$loading({
        lock: true,
        text: '人员数据验证中...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });
    },
    /**
     * 文件上传成功
     */
    handleUploadSuccess(response, file, fileList) {
      ////console.log(this.deptId)
      if (response.code == 0) {
        request({
          url: '/jiangjin/jiangjingrjcjlb/fileDow/' + response.data.bucketName + '/' + response.data.fileName +
            '/' + this.deptId,
          method: 'get',
        }).then((response) => { //
          var obj = response;
          if (obj) {
            this.$refs.dataIndex.getDataList(obj, this.deptId);
            this.loading.close()
            this.innerVisible = false;
          } else {
            this.loading.close()
            this.$message.closeAll()
            this.$message.error("数据导入错误请联系管理员")
          }
        });

      } else {
        this.$message.closeAll()
        this.$message.error('上传出错：' + response.msg)
      }
    },


  }
}

</script>
